package com.wave.traffic.controller;

import com.wave.traffic.enums.NetControllerEnum;
import com.wave.traffic.listener.InitKND;
import com.wave.traffic.util.SocketClientUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.Socket;
import java.util.Arrays;
import java.util.StringJoiner;


/**
 * @author linhui
 * @date 2023/5/8 16:31
 * @version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/api")
public class TestController {

    @RequestMapping("/mac/{ip}")
    public String aa(@PathVariable String ip) {
        Socket socket100 = InitKND.socketMap.get(ip);
        StringJoiner joiner = new StringJoiner(":");
        String string = SocketClientUtil.sendData(socket100, "000100000006FF0300640003");
        String[] split1 = string.split(",");
        split1 = Arrays.stream(split1).skip(9).toArray(String[]::new);
        for (String s : split1) {
            joiner.add(s.replace("0x", ""));
        }
        String mac = joiner.toString().toLowerCase();
        return mac;
    }

    @RequestMapping("/bb")
    public String bb() {
        Socket socket101 = InitKND.socketMap.get("192.168.1.101");
        StringJoiner joiner = new StringJoiner(":");
        String string = SocketClientUtil.sendData(socket101, "000100000006FF0300640003");
        String[] split1 = string.split(",");
        split1 = Arrays.stream(split1).skip(9).toArray(String[]::new);
        for (String s : split1) {
            joiner.add(s.replace("0x", ""));
        }

        String mac = joiner.toString().toLowerCase();
        return mac;
    }

}
